﻿	<!DOCTYPE html>
	<html lang="en">
	<head>


	<!-- TEAM STATUS -->
	<!--/HEADER -->

	<!-- PAGE -->

	<!-- /SIDEBAR -->

	<!-- /SAMPLE BOX CONFIGURATION MODAL FORM-->

	<!-- /PAGE HEADER -->
	<!-- DATA TABLES -->
	<form action="index.php?c=news&a=del&admin=1" method="post">
	<div class="row">
	<div class="col-md-12">
	<!-- BOX -->
	<div class="box border green">
	    <div class="box-title">
	        <h4><i class="fa fa-table"></i>新闻列表</h4>
	        <div class="tools hidden-xs">
	            <a href="#box-config" data-toggle="modal" class="config">
	                <i class="fa fa-cog"></i>
	            </a>
	            <a href="javascript:;" class="reload">
	                <i class="fa fa-refresh"></i>
	            </a>
	            <a href="javascript:;" class="collapse">
	                <i class="fa fa-chevron-up"></i>
	            </a>
	            <a href="javascript:;" class="remove">
	                <i class="fa fa-times"></i>
	            </a>
	        </div>
	    </div>
	    <div class="box-body">
	    <form role="form" >
	    <thead>
	                <tr>

	              <input type="checkbox" class="quanx" name="checked">全选

                <select name="type">
                  <option value="0">请选择</option>
                  <option value="1">批量删除</option>
                  <option value="2">批量审核通过</option>
                   <option value="3">批量审核未通过</option>

                </select>
                <input class="btn-del" type="submit" value="提交">
                <input type="button" class="btn-add" value="添加一行">
	                </tr>
	            </thead>

	        <table id="datatable1" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">

	            <thead>
	                <tr>
	                    <th></th>
	                    <th>ID</th>
	                    <th>标题</th>
	                    <th>内容</th>
	                    <th>新闻类型</th>
	                    <th>发布者</th>
	                    <th>新闻作者</th>
	                    <th>新闻图片</th>
	                    <th>审核</th>
	                    <th>管理员</th>
	                    <th>发布日期</th>
	                </tr>
	            </thead>
	            <tbody>
	            <?php foreach($result as $value){?>
	                <tr class="gradeX">
	                    <td><input type="checkbox" name="checked[]" value="<?php echo $value['id']?>"></td>
	                    <td><?php echo $value['id']?></td>
	                    <td filed="title" class="db_edit"><?php echo $value['title']?></td>
	                    <td  filed="content" class="db_edit"><?php echo $value['content']?></td>
	                    <td filed="type" class="db_edit"><?php echo $value['type']?></td>
	                    <td><?php echo $value['promulgator']?></td>
	                    <td><?php echo $value['author']?></td>
	                    <td ><img src="<?php echo $value['news_photo']?>" width="50" height="50"></td>
	                    <td>

	                    <button  status="<?php echo $value['auditing'];?>" class="btn
	                    <?php echo($value['auditing']==1)?'btn-success':'btn-danger'?> bnt-xs">
	                    <i class="fa <?php echo ($value['auditing']==1)?'fa-check':'fa-times'; ?>"  ></i>

	                    </button>
	                     <input type="hidden" name="status[]" value="<?php echo $value['auditing'];?>">

	                    </td>
	                    <td>
	                        <a href="index.php?c=news&a=edit&admin=1&id=<?php echo $value['id']?>" class="btn btn-info"><i class="fa fa-pencil-square-o"></i> 编辑</a>

	                        <a href="index.php?c=news&a=del&admin=1&id=<?php echo $value['id']?>" onclick="return confirm('真的要删除吗？')" class="btn btn-2g btn-danger"><i class="fa fa-trash-o"></i> 删除</a>

	                    </td>
	                    <td><?php echo $value['date']?></td>
	                </tr>
	                <?php } ?>


	            </tbody>

	        </table>
	    <div class="row"><div class="col-sm-12">
	         <div class="pull-left">
	            <div class="dataTables_info" id="datatable1_info">Showing 1 to 10 of 57 entries</div>
	         </div>
	         <div class="pull-right">
	             <div class="dataTables_paginate paging_bs_full" id="datatable1_paginate">
	                   <ul class="pagination">


	                          <?php echo $pages; ?>

	                     </ul>
	                 </div>
	             </div>

	             <div class="clearfix"></div>
	             </div>
	          </div>

	        </form>


	    </div>
	</div>
	<!-- /BOX -->
 	</div>
	</div>
	</form>
	<script src="resources/admin/js/jquery/jquery-2.0.3.min.js""></script>
	<script type="text/javascript">

//添加一行
	$(function(){

        $('.btn-add').click(function(){


		     	    var html='';

		     	    html+='<tr class="gradeX">';

		             html+='<td><input type="checkbox" name="checked[]" value=""></td>';
		             html+='<td></td>';
		             html+='<td filed="title" class="db_edit"><input type="text" name="title" value="" ></td>';
		             html+='<td  filed="content"class="db_edit"><input type="text" name="content" value="" ></td>';
		             html+='<td filed="type" class="db_edit"></td>';
		             html+='<td><input type="text" name="type" ></td>';
		             html+='<td></td>';
		             html+='<td ><img src=""></td>';
		             html+='<td>';
		             html+='<select>';
	                 html+='<option value="1">通过</option>';
	                 html+='<option value="0">不通过</option>';
	                 html+='</select>';
		             html+='<button type="button" tp class="btn  bnt-xs"><i class="fa "></i></button></td>';
		             html+='<td><a href="javascript:;" id="add" class="btn btn-info"><i class="fa fa-pencil-square-o"></i> 保存</a>';
		             html+='<a href=""  class="btn btn-2g btn-danger"><i class="fa fa-trash-o"></i> 取消</a> </td>';
		             html+='<td></td>';
		             html+='</tr>';

		             $('tbody').prepend(html);
		            // var newsType = new inArray();
             $('#add').click(function(){

              var  title=$(this).parent().parent().find('input[name=title]').val();
              var  content=$(this).parent().parent().find('input[name=content]').val();
              var  type=$(this).parent().parent().find('input[name=type]').val();
             	$.ajax({

 				url: 'index.php?c=news&a=add&admin=1',
 				type: 'post',
 				data: {'title':title,'content':content,'type':type,fall:2},
 				// dataType:'json',
 				success:function(json){
// alert(json);return;
 					if(json>0){
					   alert('修改成功')
					}else{
					 alert('修改失败')
					}
                    window.location.reload();
 				}



                    })
     })


  })



	$('.pagination ').on('click','li a',function(){

	// var url = $(this).find('a').attr('href');
	var url = $(this).attr('href');
	//var url = 'index.php?admin=1&c=index&a=index';

	$.ajax({

	type:'get',
	url:url,
	dataType:'json',

	success:function(json){

	// console.console.log(json[0].title);
	//
	var html='';
	var result = json.result;
	for(var i in result){
	html+='<tr class="gradeX">';
	html+='<td><input type="checkbox" name="xz"></td>';
	html+='<td>'+result[i].id+'</td>';
	html+='<td filed="title" class="db_edit">'+result[i].title+'</td>';
	html+='<td filed="content" class="db_edit">'+result[i].content+'</td>';
	html+='<td filed="type" class="db_edit">'+result[i].type+'</td>';
	html+='<td>'+result[i].promulgator+'</td>';
	html+='<td>'+result[i].promulgator+'</td>';
	html+='<td>'+result[i].news_photo+'</td>';
	var cls = (result[i].auditing==1)?'btn-success':'btn-danger';
	var icon = (result[i].auditing==1)?'fa-check':'fa-times';
	html+='<td><button status="'+result[i].auditing+'"  class="btn '+cls+' bnt-xs"><i class="fa '+icon+'"></i></button></td>';

	html+='<td>';
	html+='<a href="index.php?c=news&a=edit&admin=1&id='+result[i].id+'" class="btn btn-info"><i class="fa fa-pencil-square-o"></i> 编辑</a>';

	html+='<a href="index.php?c=news&a=del&admin=1&id='+result[i].id+'" onclick="return confirm(真的要删除吗？)" class="btn btn-2g btn-danger">';
	html+='<i class="fa fa-trash-o"></i> 删除</a>';

	html+='</td>';
	html+='</tr>';
	}
	// console.log(html);
	$('tbody').html(html);//代替原来已经显示的数据
	$('.pagination').html(json.pages);
	}

	})
	return false;

	})
	//双击编辑列表数据
	//抓取类名等于db_edit的所有td标签绑定双击事件
	$('tbody ').on('dblclick','.db_edit',function(event) {

	var len = $('tbody :text').length;

	if(len>0){

	var val = $('tbody :text').val();

	$('tbody :text').parent().text(val);
	}
	//获取双击编辑的数据
	var txt = $(this).text();

	var inp = '<input type="text" value="'+txt+'"/>';
	//将要编辑的td内容替换成输入框的形式显示
	$(this).html(inp);
	//获取焦点事件
	$('tbody :text').focus();
	//绑定失去焦点事件
	$('tbody :text').blur(function(event) {
	//当input标签失去焦点则获取失去焦点的input标签val值
	var val = $(this).val();


	//获取要修改的字段名
	var filed = $(this).parent().attr('filed');

	var id =  $(this).parent().parent().find('td:eq(1)').text();
	//找到失去焦点input标签的父级，然后用编辑过的新数据替换掉父级（td）的文本内容，让显示效果恢复成原来的状态

	$(this).parent().text(val);

	$.ajax({
	type:'post',
	url:'index.php?c=news&a=edit&admin=1&id='+id,
	data:{
	val:val,
	filed:filed,
	},
	success:function(row){
	if(row>0){
	   alert('修改成功')
	}else{
	 alert('修改失败')
	}
	}
	})
	});
	});

	       /*全选*/
	$('.quanx').click(function(){
		// alert(123);
          //判断当前是否是选中状态
		 if($(this).prop('checked')){
		 	$('tbody :checkbox').prop('checked',true);
		 }else{
		 	$('tbody :checkbox').prop('checked',false);
		 }

	})

    //审核1
	$('tbody').on('click','button.bnt-xs',function(){

		var status=$(this).attr('status');

        var id =  $(this).parent().parent().find('td:eq(1)').text();

		if($(this).attr('status')>0){
               var status=0;
		}else{
			var status=1;
		}

          //把当前操作对象存在临时变量中
          var obj = $(this);
          // console.log(status);

        $.ajax({
        	url: 'index.php?c=news&a=edit&admin=1',
        	type: 'post',
        	data: {
                'id':id,
        		'auditing':status,
        },

        	success:function(json){

                 if(json>0){

                    if(status>0){
 // console.log(1);
                      obj.removeClass('btn-danger');

                      obj.addClass('btn-success');

                      obj.find('i').removeClass('fa-times');

                      obj.find('i').addClass('fa-check');
                    }else{
                    	 // console.log(2);
                    	obj.removeClass('btn-success');

                      obj.addClass('btn-danger');

                       obj.find('i').removeClass('fa-check');

                      obj.find('i').addClass('fa-times');
                    }
                 }
        	}
        })




        return false;
	})

})



	</script>

